const { createStore } = require("redux")
const  { ADD_COUNT, CHANGE_NAME } = require('./constants')

const initialState = {
  name: '张三',
  count: 0
}

function reducer(state = initialState, action) {
  switch(action.type) {
    case CHANGE_NAME:
      // 不能直接修改state.name，否则就不是纯函数了
      return { ...state, name: action.name }
    case ADD_COUNT:
      return { ...state, count: state.count + action.num }
    default:
      return state
  }
}

module.exports = reducer